/**
 * https://leetcode-cn.com/problems/permutations/
 * @param {number[]} nums
 * @return {number[][]}
 */
 var permute = function(nums) {
  const results = [];
  function dfs(nums, current) {
      if (!nums.length) {
          results.push([...current]);
          return;
      }
      for (let i = 0; i < nums.length; i++) {
          current.push(nums[i]);
          nums.splice(i, 1);
          dfs(nums, current);
          nums.splice(i,0, current.pop());
      }
  }
  dfs(nums, []);
  return results;
};
